/**
 * 询价.COM v1.0.0
 * http://xun-jia.com/
 *
 * Copyright (c) 2009 
 * 四川漾天空网络科技有限公司
 * 成都市天府软件园A3栋2楼
 *
 */
package com.xunjia.action;

import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;
import org.apache.struts2.interceptor.ServletRequestAware;
import org.apache.struts2.interceptor.ServletResponseAware;
import org.apache.struts2.interceptor.SessionAware;

import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.interceptor.annotations.Before;
import com.xunjia.util.Constants;
import com.xunjia.util.StringUtil;
import com.yam.michael.hibernate.pojo.Pojo;

/**
 * 
 * @author Mark
 * 
 * @Email Mark_yang@xun-jia.com
 * 
 * @Date 2009-4-2 上午10:00:47
 * 
 */
public class XunJiaActionSupport extends ActionSupport implements SessionAware, ServletRequestAware, ServletResponseAware {
	// 日志
	private static final Logger logger = Logger.getLogger(XunJiaActionSupport.class);
	private static final long serialVersionUID = 5046132969671817470L;
	// 会话
	protected Map<String, Object> session;
	// 请求
	protected HttpServletRequest request;
	// 响应
	protected HttpServletResponse response;
	// 當前登陸用戶
	protected Object user;
	// 登陸用戶類型(企業用戶,個人用戶)
	protected String userType;
	// 所屬企業ID
	protected String belongsCompanyID;
	// 管理员类型
	protected String managerLevel;
	// 用户ID
	protected String userID;

	/**
	 * @return the userID
	 */
	public String getUserID() {
		return userID;
	}

	/**
	 * @param userID
	 *            the userID to set
	 */
	public void setUserID(String userID) {
		this.userID = userID;
	}

	/**
	 * @return the managerLevel
	 */
	public String getManagerLevel() {
		return managerLevel;
	}

	/**
	 * @param managerLevel
	 *            the managerLevel to set
	 */
	public void setManagerLevel(String managerLevel) {
		this.managerLevel = managerLevel;
	}

	/**
	 * @return the belongsCompanyID
	 */
	public String getBelongsCompanyID() {
		return belongsCompanyID;
	}

	/**
	 * @param belongsCompanyID
	 *            the belongsCompanyID to set
	 */
	public void setBelongsCompanyID(String belongsCompanyID) {
		this.belongsCompanyID = belongsCompanyID;
	}

	/**
	 * @return the userType
	 */
	public String getUserType() {
		return userType;
	}

	/**
	 * @param userType
	 *            the userType to set
	 */
	public void setUserType(String userType) {
		this.userType = userType;
	}

	/**
	 * 验证用户是否已登陆
	 * 
	 * @throws Exception
	 */
	@Before
	public void validteLogin() throws Exception {
		// 獲取登陸用戶
		user = session.get(Constants.SESSION_USER);
		logger.info(user);
		// 如果用戶為NULL,則表示還沒有登陸
		if (user == null || !(user instanceof Pojo)) {
			logger.info("用户未登陆");
			throw new Exception("用户未登陆!");
		}
		// 獲取用戶類型(企業,個人)
		userType = (String) session.get(Constants.USER_TYPE);
		// 如果為企業用戶
		belongsCompanyID = StringUtil.getString(session.get(Constants.SESSION_USER_BELONG_COMPANY_ID));
		// 管理员级别
		managerLevel = StringUtil.getString(session.get(Constants.SESSION_SUB_MANAGER));
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.apache.struts2.interceptor.SessionAware#setSession(java.util.Map)
	 */
	@Override
	public void setSession(Map<String, Object> session) {
		this.session = session;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.apache.struts2.interceptor.ServletRequestAware#setServletRequest( javax.servlet.http.HttpServletRequest)
	 */
	@Override
	public void setServletRequest(HttpServletRequest request) {
		this.request = request;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.apache.struts2.interceptor.ServletResponseAware#setServletResponse (javax.servlet.http.HttpServletResponse)
	 */
	@Override
	public void setServletResponse(HttpServletResponse response) {
		this.response = response;
	}

}
